<script type="text/javascript">
    $(document).ready(function(){
        var pageIndex = 0;
        var tempPageIndex = 0;
        var pageSize = 12;
        loadData();
        function loadData() {
            $.ajax({
                url : "dataToJson.php",
                type: "post",
                data : {pageIndex:pageIndex, pageSize:pageSize,loadData:'Home'},
                dataType : "json",
    			beforeSend : function(){
    				$('#loading').show();
    			},
    			complete : function(){
    				$('#loading').hide();
    			}
            })
            .done(function(dataJson){
                var html = "";
                $.each(dataJson, function(index, item){
                    var name = item.name;
                    html += '<li class="product">';
                    html += '<div class="product-item">';
                    html += '<div class="name_thumb"> <a title="' + name + '" href="/khohangtot/product-detail/' + item.id + '/' + item.linkFriendly + '.htm" class="title">';
                    html += name.substring(0,65) +'..</a>';
                    html += '<img title="'+ name +'"  src="/khohangtot/images/icon_hot_png.gif"/>';
                    html += '</div><!--end .name_thumb-->';
                    html += '<a title="'+ name +'" href="/khohangtot/product-detail/' + item.id + '/' + item.linkFriendly + '.htm" class="thumb">';
                    if(item.image == '') {
                        html += '<img title="'+ name +'"  src="/khohangtot/images/spm.jpg" border="0" />';
                    } else {
                        html += '<img title="'+ name +'"  src="/khohangtot/images/product/images/'+ item.image +'" border="0" />';
                    }
                    html += '</a> <span>Giá bán: </span><span class="price">&nbsp';
                    html += item.priceFormat;
                    html += '&nbsp;</span>';
                    html += '<a title="'+ name +'" onclick="javascript:return confirm(\'Bạn có muốn mua sản phẩm này không ?\');" href="/khohangtot/' + item.id + '/add-to-cart.htm"><img title="khohangtot| do gia dung"  src="/khohangtot/images/chonsp.png" class="add-to-cart"/></a>';
                    html += '</div><!--end .product-item-->';
                    html += '</li>';
                });
                $('div.product-listing ul').append(html);
                pageIndex++;
            })
            .fail(function(jqXHR, textStatus, errorThrown){
                console.log(textStatus);
            });
        }
        $(window).scroll(function() {
        if($(window).scrollTop() + $(window).height() == $(document).height()) {
            if(pageIndex > tempPageIndex) {
		      loadData();
              tempPageIndex = pageIndex;
            }
	    }
	});
    });
</script>
<?
$cat = 0;
if ($_REQUEST['cat'] != '')
    $cat = killInjection($_REQUEST['cat']);
?>
<div class="product-listing">
  <div class="title_left_bg"></div>
  <div class="title_center_bg">
    <div class="title_center_icon"></div>
    <? include ("module/processTitle.php") ?>
  </div>
  <div class="title_right_bg"></div>
  <ul class="clearfix">
  </ul>
  <!--end .clearfix--> 
</div>
<!--end .product-listing-->
<div id="loading"><img src="/khohangtot/images/loading.gif" alt="Loading..." title="kho hang tot | do gia dung"/></div>